package com.care.system.server.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.care.system.common.request.RecordRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.care.common.log.annotation.Log;
import com.care.common.log.enums.BusinessType;
import com.care.common.security.annotation.RequiresPermissions;
import com.care.system.common.domain.TRecord;
import com.care.system.server.service.ITRecordService;
import com.care.common.core.web.controller.BaseController;
import com.care.common.core.domain.Result;
import com.care.common.core.utils.poi.ExcelUtil;
import com.care.common.core.web.page.TableDataInfo;

/**
 * 钱包明细Controller
 *
 * @author 李光耀负责
 * @date 2024-03-25
 */
@RestController
@RequestMapping("/record")
public class TRecordController extends BaseController
{
    @Autowired
    private ITRecordService tRecordService;

    /**
     * 查询钱包明细列表
     */
    @PostMapping("/recordList")
    public TableDataInfo recordList(RecordRequest recordRequest)
    {
        startPage();
        List<TRecord> list = tRecordService.selectRecordList(recordRequest);
        return getDataTable(list);
    }

    /**
     * 导出钱包明细列表
     */
    @RequiresPermissions("system:record:export")
    @Log(title = "钱包明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TRecord tRecord)
    {
        List<TRecord> list = tRecordService.selectTRecordList(tRecord);
        ExcelUtil<TRecord> util = new ExcelUtil<TRecord>(TRecord.class);
        util.exportExcel(response, list, "钱包明细数据");
    }

    /**
     * 获取钱包明细详细信息
     */
    @RequiresPermissions("system:record:query")
    @GetMapping(value = "/{recordId}")
    public Result getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(tRecordService.selectTRecordByRecordId(recordId));
    }

    /**
     * 新增钱包明细
     */
    @RequiresPermissions("system:record:add")
    @Log(title = "钱包明细", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody TRecord tRecord)
    {
        return toAjax(tRecordService.insertTRecord(tRecord));
    }

    /**
     * 修改钱包明细
     */
    @RequiresPermissions("system:record:edit")
    @Log(title = "钱包明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody TRecord tRecord)
    {
        return toAjax(tRecordService.updateTRecord(tRecord));
    }

    /**
     * 删除钱包明细
     */
    @RequiresPermissions("system:record:remove")
    @Log(title = "钱包明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public Result remove(@PathVariable Long[] recordIds)
    {
        return toAjax(tRecordService.deleteTRecordByRecordIds(recordIds));
    }
}
